<!-- Modal -->
<div class="modal fade " id="addDebtModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">债务维护</h3>
            </div>
            <!-- /.box-header -->
            <!-- form start -->
            <form class="form-horizontal">
                <div class="box-body">
                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">用户姓名</label>
                        <div class="col-sm-7">
                            <input id="addCustModel_name" type="text" class="form-control" style="width: 100%;" >
                        </div>
                        <input id="addCustModel_id" type="hidden">
                    </div>

                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">性别</label>
                        <div class="col-sm-7">
                            <select id="addCustModel_sex" style="width: 150px"  class="form-control select2"  >
                            </select>
                        </div>
                        <input id="addCustModel_birthday" type="hidden">
                    </div>
                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">生日</label>
                        <div class="col-sm-7">
                            <input id="addCustModel_birth" type="text" class="form-control" style="width: 100%;" >
                        </div>
                    </div>
                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">电话</label>
                        <div class="col-sm-7">
                            <input id="addCustModel_phone" type="text" class="form-control" style="width: 100%;" >
                        </div>
                    </div>
                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">邮箱</label>
                        <div class="col-sm-7">
                            <input id="addCustModel_email" type="text" class="form-control" style="width: 100%;" >
                        </div>
                    </div>
                    <div class="form-group" id="weightDiv">
                        <label for="inputEmail3" class="col-sm-2 control-label">密码</label>
                        <div class="col-sm-7">
                            <input id="addCustModel_password" type="text" class="form-control" style="width: 100%;" >
                        </div>
                    </div>
                </div>
                <!-- /.box-body -->
                <div class="box-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary pull-right"
                            onclick="addDebtModel_save()">保存
                    </button>
                </div>
                <!-- /.box-footer -->
            </form>
        </div>
    </div>
</div>
<script>
    function addDebtModel_init() {

        $("#addCustModel_id").val("");
        $("#addCustModel_name").val("");
        $("#addCustModel_sex").empty();
        $("#addCustModel_birth").val("");
        $("#addCustModel_phone").val("");
        $("#addCustModel_email").val("");
        $("#addCustModel_password").val("");
    }
    function addDebtModel_setValue(index) {
        var url1 = "/cust/select/addcust" ;
        if(index === -1) {
            setFormValue(url1,"addCustModel_sex") ;
        } else {
            var options = $("#table").bootstrapTable("getData");

            // alert(JSON.stringify(options));

            var row = options[index];
            // alert(index);
            $("#addCustModel_id").val(row.id);
            $("#addCustModel_name").val(row.name);
            $("#addCustModel_birth").val(row.birth);
            $("#addCustModel_phone").val(row.phone);
            $("#addCustModel_email").val(row.email);
            $("#addCustModel_password").val(row.password);


            setFormValue(url1,"addCustModel_sex",row.sex) ;
        }
    }


    function addDebtModel_save() {
        var data = {
            id: val("addCustModel_id"),
            name: val("addCustModel_name"),
            sex: val( "addCustModel_sex","select"),
            birth:val( "addCustModel_birth",),
            phone: val("addCustModel_phone"),
            email: val("addCustModel_email"),
            password: val("addCustModel_password")
        };
        var url = "/cust/save";
        postReq(url, data, function (result) {
            if (result.success) {
                toastr['success']('操作成功', '提示');
                $("#table").bootstrapTable("refresh");
                $("#addCustModel").modal("hide");
            } else {
                toastr['error'](result.msg, '提示');
            }
        });
    }
</script>
